<?php
class indexController extends Controller{
    public function __construct(){
        parent::__construct();

    }

    public function index($tpl){
        echo 'welcome';
        $member=new Model('member');
        //$member->insert("insert into __member__ %s",array('username'=>'11','password'=>'22','xx'=>'xx'));
        //$member->update("update __member__ set %s where itemid=:itemid",['password'=>'888'],['itemid'=>2]);
        //$member->i(['username'=>'a','password'=>'b']);
        //p($member->get_column("select itemid from __member__"));
        $article=new Model('article');
        p($article->s());
        p($article->find("select * from __article__ where itemid=:itemid",['itemid'=>2]));
        p($article->f(2));
        echo $article->last_sql();

        $articleModel=load_model('article');
        p($articleModel->s());

        //M('member');
        $m=new memberModel();
        new sys_conf();
        new sys_conf();
        include $tpl;
    }

    public function hello($tpl){
        echo 'hello';
    }
    public function test(){
        $article=new Model('article');
        $data=$article->select("select * from __TB__",array(),20);
        p($data);
    }
    public function valid(){
        $data=array(
            //'goods_name'=>111,
        );
        $rules=array(
            array('goods_name',1,'必须有商品名','require'),
        );
        $validation=new Validation($data,$rules);
        if(!$validation->valid()){
            echo $validation->get_error();
        }
    }
	public function tpl_test(){
		// include $tpl;
		$data=array(
			array('title'=>'aaa','content'=>'bbb'),
			array('title'=>'bbb','content'=>'bbb'),
		);
		
		$username='张三';
		
		$tag=true;
		
		include template(get_defined_vars());
	}
	public function attach_test(){
		$query=new Attach('itemid',['itemid','title','content']);
		$sql=$query->table('__article__')->where("status=3 and username=:username")->order("itemid asc")->limit("20")->select();
		echo $sql;
		echo "<br>";
		$query=new Attach('itemid',['itemid','title','content']);
		$sql=$query->table('__article__')->field('title')->where("status=3 and username=:username")->order("itemid asc")->limit("20")->select();
		echo $sql;
		echo "<br>";
		$query=new Attach('itemid',['itemid','title','content']);
		$sql=$query->table('__article__')->where("level=:level")->find();
		echo $sql;
		echo "<br>";
		
		$query=new Attach('itemid',['itemid','title','content']);
		$sql=$query->table('__article__')->where("level=:level")->total();
		echo $sql;
		echo "<br>";
		
		$query=new Attach('itemid',['itemid','title','content']);
		$sql=$query->table('__article__')->insert(['title'=>'aaa','content'=>'bbb']);
		echo $sql;
		echo "<br>";
		
		$query=new Attach('itemid',['itemid','title','content']);
		$sql=$query->table('__article__')->where("addtime>:addtime")->update(['title'=>'aaa','content'=>'bbb']);
		echo $sql;
		echo "<br>";
		$query=new Attach('itemid',['itemid','title','content']);
		$sql=$query->table('__article__')->where("addtime>:addtime")->delete();
		echo $sql;
		echo "<br>";
		$query=new Attach('itemid',['itemid','title','content']);
		$sql=$query->table('__article__')->limit(2)->delete();
		echo $sql;
		echo "<br>";
	}

} 
